my $pattern = $ARGV[0];

#nb perl glob list file name match pattern
my @pl_sfi = glob($pattern);

if ( ( scalar @pl_sfi ) == 0 ) {
    print "INPUT ERROR: found no files to convert.\n";
    exit 1;
}

#nb perl match file name pattern
if ( ( scalar @pl_sfi ) == 1 ) {
    if ( !-d $pl_sfi[0] && $pl_sfi[0] !~ /.*.pl/ ) {
        print
            "INPUT ERROR: please specify either an existing directory or an existing *.pl file.\n";
        exit 1;
    }
    if ( -d $pl_sfi[0] ) {
        @pl_sfi = glob( $pl_sfi[0] . "/*.pl" );
        if ( ( scalar @pl_sfi ) == 0 ) {
            print "INPUT ERROR: found no files to convert.\n";
            exit 1;
        }
    }
}

#nb use filter perl
if ( ( scalar @pl_sfi ) > 1 ) {
    @pl_sfi = filter( sub { $_ =~ /.*.pl/ }, @pl_sfi );
}

if ( ( scalar @pl_sfi ) > 1 ) {
    map { runSelf($_); } @pl_sfi;
    exit 0;
}

print "/myJob/publish $pl_sfi[0]\n";

#nb sub filter perl
sub filter {
    my ( $cond, @coll ) = @_;
    my @out;
    map { push( @out, $_ ) if $cond->($_) } @coll;
    return @out;
}

sub runSelf {
    my $pl  = shift;
    my $sfi = $pl;

    #nb perl search replace string text
    $sfi =~ s/\.pl$/.sfi/;

    if ( !-f $sfi ) {
        my $self = "gensfi";
        print "runProcedure $self $sfi\n";
    }
}
